package com.fxd.dao;

import com.fxd.doman.Account;
import org.apache.ibatis.annotations.One;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.mapping.FetchType;

import java.util.List;

/**
 * @auther fuxudong
 * @date 2021/1/10 - 15:25
 */
public interface IAccountDao {
    //查询所有账户，并且获取每个账户所属的用户信息
    @Select("select*from account")
    @Results(id = "accountMap", value = {
            @Result(id = true, column = "id", property = "id"),
            @Result(column = "uid", property = "uid"),
            @Result(column = "money", property = "money"),
            //select方法全限定名称，column表示参数，fetchtype，eager:立即加载，lazy:延迟加载
            @Result(property = "user", column = "uid", one = @One(select = "com.fxd.dao.IUserDao.findById", fetchType = FetchType.EAGER))

    })
    List<Account> findAll();

    @Select("select*from account where uid=#{userId}")
    List<Account> findById(Integer userId);
}
